package shortener

import (
	"math/rand"
	"strings"
	"time"
)

const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

func init() {
	rand.Seed(time.Now().UnixNano())
}

// GenerateShortLink 生成指定长度的短链字符串
func GenerateShortLink(length int) string {
	var sb strings.Builder
	for i := 0; i < length; i++ {
		idx := rand.Intn(len(charset))
		sb.WriteByte(charset[idx])
	}
	return sb.String()
}
